using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace ERPBackend.Models
{
    public class SalesContract : BaseModel
    {
        /// <summary>
        /// 合同编号
        /// </summary>
        [Required]
        [MaxLength(50)]
        public string ContractCode { get; set; }

        /// <summary>
        /// 合同名称
        /// </summary>
        [Required]
        [MaxLength(255)]
        public string ContractName { get; set; }

        /// <summary>
        /// 客户ID
        /// </summary>
        [Required]
        public int CustomerId { get; set; }

        /// <summary>
        /// 客户
        /// </summary>
        [ForeignKey("CustomerId")]
        public Customer Customer { get; set; }

        /// <summary>
        /// 签订日期
        /// </summary>
        [Required]
        public DateTime SigningDate { get; set; }

        /// <summary>
        /// 生效日期
        /// </summary>
        public DateTime? EffectiveDate { get; set; }

        /// <summary>
        /// 失效日期
        /// </summary>
        public DateTime? ExpiryDate { get; set; }

        /// <summary>
        /// 合同状态（0:待审核, 1:已审核, 2:已终止, 3:已作废）
        /// </summary>
        [Required]
        public int Status { get; set; }

        /// <summary>
        /// 合同总金额
        /// </summary>
        [Column(TypeName = "decimal(18,4)")]
        public decimal TotalAmount { get; set; }

        /// <summary>
        /// 已收款金额
        /// </summary>
        [Column(TypeName = "decimal(18,4)")]
        public decimal ReceivedAmount { get; set; }

        /// <summary>
        /// 未收款金额
        /// </summary>
        [Column(TypeName = "decimal(18,4)")]
        public decimal UnpaidAmount { get; set; }

        /// <summary>
        /// 付款条件
        /// </summary>
        [MaxLength(255)]
        public string PaymentTerms { get; set; }

        /// <summary>
        /// 交付条件
        /// </summary>
        [MaxLength(255)]
        public string DeliveryTerms { get; set; }

        /// <summary>
        /// 合同条款
        /// </summary>
        public string ContractTerms { get; set; }

        /// <summary>
        /// 审核人ID
        /// </summary>
        public int? ApprovedBy { get; set; }

        /// <summary>
        /// 审核时间
        /// </summary>
        public DateTime? ApprovedTime { get; set; }

        /// <summary>
        /// 终止原因
        /// </summary>
        public string TerminationReason { get; set; }

        /// <summary>
        /// 终止人ID
        /// </summary>
        public int? TerminatedBy { get; set; }

        /// <summary>
        /// 终止时间
        /// </summary>
        public DateTime? TerminatedTime { get; set; }

        /// <summary>
        /// 销售合同明细
        /// </summary>
        public List<SalesContractItem> SalesContractItems { get; set; } = new List<SalesContractItem>();
    }
}